﻿using DevExpress.LookAndFeel.Design;
using DevExpress.Skins;
using DevExpress.Skins.Info;
using DevExpress.UserSkins;
using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

using DotNetExtensions.AspNet.SQLites;
using System.IO;

namespace Habi.Solver
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            AppDomain.CurrentDomain.AssemblyResolve += OnCurrentDomainAssemblyResolve;
            CultureInfo cultureInfo = new CultureInfo("zh-cn");
            DateTimeFormatInfo dateTimeFormatInfo = (DateTimeFormatInfo)cultureInfo.DateTimeFormat.Clone();
            dateTimeFormatInfo.ShortDatePattern = DateTimeFormat.ShortDateTime;
            cultureInfo.DateTimeFormat = dateTimeFormatInfo;
            Application.CurrentCulture = cultureInfo;

            DevExpress.XtraEditors.WindowsFormsSettings.SetDPIAware();
            DevExpress.XtraEditors.WindowsFormsSettings.EnableFormSkins();
            DevExpress.XtraEditors.WindowsFormsSettings.EnableMdiFormSkins();
            DevExpress.XtraEditors.WindowsFormsSettings.AllowPixelScrolling = DefaultBoolean.True;
            float fontSize = 11f;
            DevExpress.XtraEditors.WindowsFormsSettings.DefaultFont = new Font("Segoe UI", fontSize);
            DevExpress.XtraEditors.WindowsFormsSettings.DefaultMenuFont = new Font("Segoe UI", fontSize);

            Application.CurrentCulture = CultureInfo.GetCultureInfo("zh-cn");
            Localizer.Active = new LocalizationCHS();
            SkinManager.EnableFormSkins();
            // BonusSkins.Register();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            SQLiteBuilder.Default.Initialize(SQLiteConnectionFactory.Default.Create(ConnectionString));


            MainForm = new FormMain() { Icon = AppIcon };
           
            if (Program.IsTablet) SetupAsTablet();
            Application.Run(MainForm);
        }
        static Assembly OnCurrentDomainAssemblyResolve(object sender, ResolveEventArgs args)
        {
            return null;
        }
        private static void SetupAsTablet()
        {
            MainForm.ShowNavPanel();
            MainForm.FormBorderStyle = FormBorderStyle.None;
            MainForm.WindowState = FormWindowState.Normal;
            DevExpress.XtraEditors.WindowsFormsSettings.PopupMenuStyle = PopupMenuStyle.RadialMenu;
            DevExpress.Utils.TouchHelpers.TouchKeyboardSupport.EnableTouchKeyboard = true;
        }
        static bool? isTablet = true;
        public static bool IsTablet
        {
            get
            {
                if (isTablet == null)
                {

                    isTablet = false;
                }
                return isTablet.Value;
            }
        }
        public static FormMain MainForm
        {
            get;
            private set;
        }

        public static Icon AppIcon
        {
            get { return ResourceImageHelper.CreateIconFromResourcesEx("Habi.Solver.Resources.Favicon.ico", typeof(FormMain).Assembly); }
        }

        public static string ConnectionString
        {
            get
            {
                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "data.db3");
                return string.Format("Data Source={0};Version=3;", path);
            }
        }
    }
    public struct DateTimeFormat
    {
        public const string FullDateTime = "yyyy/MM/dd HH:mm:ss";
        public const string ShortDateTime = "yyyy/MM/dd HH:mm";
        public const string Date = "yyyy/MM/dd";
    }
    public class LocalizationCHS : Localizer
    {
        public override string GetLocalizedString(StringId id)
        {
            switch (id)
            {
                case StringId.XtraMessageBoxCancelButtonText:
                    return "取消";
                case StringId.XtraMessageBoxOkButtonText:
                    return "确定";
                case StringId.XtraMessageBoxYesButtonText:
                    return "是";
                case StringId.XtraMessageBoxNoButtonText:
                    return "否";
                case StringId.XtraMessageBoxIgnoreButtonText:
                    return "忽略";
                case StringId.XtraMessageBoxAbortButtonText:
                    return "中止";
                case StringId.XtraMessageBoxRetryButtonText:
                    return "重试";
                default:
                    return base.GetLocalizedString(id);
            }
        }
    }
}
